/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.univcasa.managing.impl;

import com.univcasa.db.model.ComptePersonnel;
import com.univcasa.managing.ComptesPersManager;
import com.univcasa.managing.LdapDBManager;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import javax.naming.ldap.ManageReferralControl;

/**
 *
 * @author Work
 */
public class DBPersManagerImpl {

    private static String DRIVER = "com.mysql.jdbc.Driver";
    private static String USER = "root";
    private static String PASS = "mayapass";
    private static String URL = "jdbc:mysql://172.16.1.20:3306/issam";
    private Connection con;


    public DBPersManagerImpl() {
        try{
            Class.forName( DRIVER );
        }catch (ClassNotFoundException e){
            e.printStackTrace();
        }
    }

    public List getListAttesta(){
        try {
            con = DriverManager.getConnection( URL, USER, PASS);
            String sql = "SELECT DRPP,cin,nom, sexe, datenaissance FROM persoagents " ;
            PreparedStatement stmt = con.prepareStatement(sql);
            ResultSet res = stmt.executeQuery();
            List resultats = new ArrayList();
            while(res.next()){                
                resultats.add( res.getString("som"));
            }
                stmt.close();
            con.close();
            return resultats;
            }
        catch (SQLException ex){
            System.out.println("ERROR SQLException");
            return null;
        }    
    }

    public void initDBPers(){
        ComptesPersManager manager = new ComptesPersManagerImpl();
        List res = getListAttesta();
        for (Iterator itr = res.iterator(); itr.hasNext();){
            ComptePersonnel pers = (ComptePersonnel) itr.next();
            pers.setEtab("NYET");
            pers.setFonction("employee");
            manager.ajouterComptePers(pers);
            System.out.println( pers );
        }
        System.out.println( res.size());        
    }
}